Skip to main content

libobs_simple\sources\linux\sources/
v4l2_input.rs

1use libobs_wrapper::{data::StringEnum, sources::ObsSourceRef};
2use num_derive::{FromPrimitive, ToPrimitive};
3
4use crate::sources::macro_helper::{define_object_manager, impl_default_builder};
5
6#[repr(i64)]
7#[derive(Clone, Copy, Debug, PartialEq, Eq, FromPrimitive, ToPrimitive)]
8/// Video color range for V4L2 input
9pub enum ObsV4L2ColorRange {
10    /// Default color range
11    Default = 0,
12    /// Partial color range (limited)
13    Partial = 1,
14    /// Full color range
15    Full = 2,
16}
17
18impl StringEnum for ObsV4L2ColorRange {
19    fn to_str(&self) -> &str {
20        match self {
21            ObsV4L2ColorRange::Default => "Default",
22            ObsV4L2ColorRange::Partial => "Partial",
23            ObsV4L2ColorRange::Full => "Full",
24        }
25    }
26}
27
28define_object_manager!(
29    #[derive(Debug)]
30    /// A source for Video4Linux2 (V4L2) camera input.
31    ///
32    /// This source captures video from V4L2 compatible devices such as webcams,
33    /// capture cards, and other video input devices on Linux.
34    struct V4L2InputSource("v4l2_input", *mut libobs::obs_source) for ObsSourceRef {
35        /// Device ID/path (e.g., "/dev/video0")
36        #[obs_property(type_t = "string")]
37        device_id: String,
38
39        /// Input number on the device
40        #[obs_property(type_t = "int")]
41        input: i64,
42
43        /// Pixel format (FOURCC code as integer)
44        #[obs_property(type_t = "int")]
45        pixelformat: i64,
46
47        /// Video standard for analog inputs
48        #[obs_property(type_t = "int")]
49        standard: i64,
50
51        /// DV timing for digital inputs
52        #[obs_property(type_t = "int")]
53        dv_timing: i64,
54
55        #[obs_property(type_t = "int")]
56        resolution: i64,
57
58        #[obs_property(type_t = "int")]
59        framerate: i64,
60
61        /// Color range setting
62        #[obs_property(type_t = "int")]
63        color_range: i64,
64
65        /// Auto-reset on timeout
66        #[obs_property(type_t = "bool")]
67        auto_reset: bool,
68
69        /// Frames until timeout
70        #[obs_property(type_t = "int")]
71        timeout_frames: i64,
72    }
73);
74
75impl V4L2InputSourceBuilder {
76    /// Set the color range using the enum
77    pub fn set_color_range_enum(self, color_range: ObsV4L2ColorRange) -> Self {
78        use num_traits::ToPrimitive;
79        self.set_color_range(color_range.to_i64().unwrap())
80    }
81}
82
83impl_default_builder!(V4L2InputSourceBuilder);